package com.umeox.moto.watch.themes.util;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.umeox.moto.watch.themes.R;
import com.umeox.moto.watch.themes.app.ThemeManager;


public class UToast {

    private static Toast toast;
    private static Toast mCustomToast;

    /**
     * 初始化Toast(消息，时间)
     */
    private static Toast initToast(CharSequence message, int duration) {
        if (null == toast) {
            toast = Toast.makeText(ThemeManager.getInstance().getContext(), message, duration);
        } else {
            //设置文字
            toast.setText(message);
            //设置存续期间
            toast.setDuration(duration);
        }
        return toast;
    }

    private static Toast initCustomToast(Context context,CharSequence message, int duration){
        View  layout = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
        TextView toast_content = (TextView) layout.findViewById(R.id.tvToastContent);
        toast_content.setText(message);
        if (null == mCustomToast) {
            mCustomToast = new Toast(context);
        }
        mCustomToast.setGravity(Gravity.FILL, 0, 0);
        mCustomToast.setDuration(duration);

        mCustomToast.setView(layout);

        return mCustomToast;
    }



    private static Toast callTip(Context context,CharSequence message, int duration){
        View layout = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
        TextView toast_content = (TextView) layout.findViewById(R.id.tvToastContent);

        toast_content.setText(message);
        if (toast == null) {
            toast = new Toast(context);
        }

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(duration);
        toast.setView(layout);

        return toast;
    }
    /**
     * 短时间显示Toast(消息 String等)
     */
    public static void showShort(CharSequence message) {
        initToast(message, Toast.LENGTH_SHORT).show();
    }


    /**
     * 短时间显示Toast（资源id)
     */
    public static void showShort(int strResId) {
        initToast(ThemeManager.getInstance().getContext().getResources().getText(strResId), Toast.LENGTH_SHORT).show();
    }

    /**
     * 长时间显示Toast(消息 String等)
     */
    public static void showLong(CharSequence message) {
        initToast(message, Toast.LENGTH_LONG).show();
    }

    /**
     * 长时间显示Toast（资源id)
     */
    public static void showLong(int strResId) {
        initToast(ThemeManager.getInstance().getContext().getResources().getText(strResId), Toast.LENGTH_LONG).show();
    }

    /**
     * 自定义显示Toast时间(消息 String等，时间)
     */
    public static void show(CharSequence message, int duration) {
        initToast(message, duration).show();
    }

    /**
     * 自定义显示Toast时间(消息 资源id，时间)
     */
    public static void show(int strResId, int duration) {
        initToast(ThemeManager.getInstance().getContext().getResources().getText(strResId), duration).show();
    }


    /**
     * 自定义显示Toast时间(消息 String等，时间)
     */
    public static void showCustomToast(Context context,CharSequence message, int duration) {
        initCustomToast(context,message, duration).show();
    }


    /**
     * 自定义显示Toast时间(消息 资源id，时间)
     */
    public static void showCustomToast(Context context,int strResId, int duration) {
        initCustomToast(context,ThemeManager.getInstance().getContext().getResources().getText(strResId), duration).show();
    }

}
